package com.yaohuan;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;

/**
 * @author YaoHuan
 * @ClassName ClientSocket
 * @Description 通过socket模拟http请求
 * @Date 2022/11/23 17:11
 */
public class ClientSocket {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 8085);
            OutputStream outputStream = socket.getOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(outputStream, "utf-8");
            StringBuffer content = new StringBuffer();
            content.append("GET /myservlet HTTP/1.1\n");
            content.append("Host: localhost:8085\n");
            content.append("\n");
            writer.write(content.toString());
            writer.flush();
            writer.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {

        }
    }
}

